package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.entity.NursingPlan;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description NursingController
 * @Author chenchuang
 * @Date 2024-08-25
 */
@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划管理")
public class NursingPlanController extends BaseController {
    @Autowired
    private NursingPlanService nursingPlanService;

    @GetMapping("/search")
    @ApiOperation("分页查询护理计划")
    public ResponseResult<PageResponse<NursingPlanVo>> getByPage(
            @ApiParam(value = "护理计划名称")
            @RequestParam(value = "name", required = false) String name,
            @ApiParam(value = "状态：0-禁用，1-启用")
            @RequestParam(value = "status", required = false) Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize){
        PageResponse<NursingPlanVo> nursingPlanVoPageInfo = nursingPlanService.getByPage(name,status,pageNum,pageSize);
        return success(nursingPlanVoPageInfo);
    }

    @PostMapping
    @ApiOperation("新增护理计划")
    public ResponseResult add( @RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.add(nursingPlanDto);
        return success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理计划")
    public ResponseResult<NursingPlanVo> getById(@PathVariable("id") Long id){
        NursingPlanVo nursingPlanVo = nursingPlanService.getById(id);
        return success(nursingPlanVo);
    }

    @PutMapping("/{id}")
    @ApiOperation("修改护理计划")
    public ResponseResult update(@PathVariable("id") Integer id, @RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.update(nursingPlanDto);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除护理计划")
    public ResponseResult delete(@PathVariable("id") Long id){
        nursingPlanService.delete(id);
        return success();
    }

    @GetMapping
    @ApiOperation("查询所有护理计划")
    public ResponseResult<List<NursingPlan>> getByPage(){
        List<NursingPlan> nursingPlanVoList = nursingPlanService.getAll();
        return success(nursingPlanVoList);
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用禁用")
    public ResponseResult updateStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status){
        nursingPlanService.enableOrDisable(id,status);
        return success();
    }



}
